package com.aal.model;

import java.util.List;

/**
 *
 * @author Hoang
 */
public class Product {
    ProductManagement pm = new ProductManagement();
    
    private int productID;

    /**
     * Set the value of productID
     *
     * @param productID new value of productID
     */
    public void setProductID(int productID) {
        this.productID = productID;
    }

    private com.aal.entity.Product product;

    /**
     * Get the value of product
     *
     * @return the value of product
     */
    public com.aal.entity.Product getProduct() {
        product = pm.getProductbyid(productID);
        return product;
    }
    
    /**
     * get a list of 4 or less products of same category
     *
     * @return the value of relatedProductList
     */
    public List<com.aal.entity.Product> getRelatedProductList() {
        pm.setCategoryid(product.getCategoryID().getCategoryID());
        List<com.aal.entity.Product> result = pm.getSearchproductbycategory();
        if (result.size()>2)
            return result.subList(0, 4);
        else
            return result;
    }
    
    private String searchQuery;

    /**
     * Set the value of searchQuery
     *
     * @param searchQuery new value of searchQuery
     */
    public void setSearchQuery(String searchQuery) {
        this.searchQuery = searchQuery;
    }

    List<com.aal.entity.Product> searchResult;
    
    public List<com.aal.entity.Product> getSearchResultList() {
        searchResult = pm.setSearchproductbyname(searchQuery);
        return searchResult;
    }
    
    public int getSearchResultPages() {
        int pages = searchResult.size() / 10;
        if (searchResult.size() % 10 != 0) pages++;
        return pages;
    }
}
